var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var util = require('util');
var signServletAgent = require('./servers/getSignServletAgent.js');
var vCodeAgent = require('./servers/verficationCodeAgent.js');
var getNumServletAgent = require('./servers/getNumServletAgent.js');
var youtouAgent = require('./servers/youtuServletAgent.js');
var hengFengAgent = require('./servers/hengFengAgent.js');
var kexinBarbrecordAgent = require('./servers/kexinbadrecordAgent.js');
var kexinBrokenAgent = require('./servers/kexinBrokenAgent.js');
var dataAgent = require('./servers/getDateAgent.js');
var smsSeverAgent = require('./servers/sendSMSServletAgent.js');
var configAgent = require('./servers/getConfigAgent.js');
var monidata = require('./servers/monidata.js');

// 创建 application/x-www-form-urlencoded 编码解析
var urlencodedParser = bodyParser.urlencoded({
    extended: false
});

/*-----------html--------*/
app.get('/dist/tltd/tradeDetail.html', function(req, res) {
    res.sendFile(__dirname + "/dist/tltd/tradeDetail.html");
});
app.get('/dist/tltd/lodin.html', function(req, res) {
    res.sendFile(__dirname + "/dist/tltd/lodin.html");
});
app.get('/dist/tltd/merchantHome.html', function(req, res) {
    res.sendFile(__dirname + "/dist/tltd/merchantHome.html");
});
app.get('/dist/tltd/orderDetail.html', function(req, res) {
    res.sendFile(__dirname + "/dist/tltd/orderDetail.html");
});
app.get('/tltd/orderDetail.html2', function(req, res) {
    res.sendFile(__dirname + "/tltd/orderDetail.html2");
});

app.get('/dist/tltd/orderDetail2.html', function(req, res) {
    res.sendFile(__dirname + "/dist/tltd/orderDetail2.html");
});
app.get('/dist/tltd/userSettings.html', function(req, res) {
    res.sendFile(__dirname + "/dist/tltd/userSettings.html");
});
app.get('/dist/tltd/staffHome.html', function(req, res) {
    res.sendFile(__dirname + "/dist/tltd/staffHome.html");
});
app.get('/dist/tltd/staffRecord.html', function(req, res) {
    res.sendFile(__dirname + "/dist/tltd/staffRecord.html");
});



/*---------js----------*/
app.get('/dist/js/tltd/libs/jquery-1.11.1.min.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/tltd/libs/jquery-1.11.1.min.js");
});
app.get('/dist/js/tltd/libs/jquery.mobile-1.4.5.min.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/tltd/libs/jquery.mobile-1.4.5.min.js");
});
app.get('/dist/js/tltd/urlValue.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/tltd/urlValue.js");
});
app.get('/dist/js/tltd/common.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/tltd/common.js");
});
app.get('/dist/js/tltd/tradeDetail.min.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/tltd/tradeDetail.min.js");
});
app.get('/dist/js/tltd/libs/iscroll.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/tltd/libs/iscroll.js");
});
app.get('/dist/js/tltd/lodin.min.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/tltd/lodin.min.js");
});
app.get('/dist/js/tltd/merchantHome.min.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/tltd/merchantHome.min.js");
});
app.get('/dist/js/tltd/orderDetail.min.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/tltd/orderDetail.min.js");
});
app.get('/dist/js/tltd/orderDetail2.min.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/tltd/orderDetail2.min.js");
});
app.get('/dist/js/tltd/userSettings.min.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/tltd/userSettings.min.js");
});
app.get('/dist/js/tltd/staffHome.min.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/tltd/staffHome.min.js");
});
app.get('/dist/js/tltd/staffRecord.min.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/tltd/staffRecord.min.js");
});


/*------css----------*/
app.get('/dist/css/tltd/page/tradeDetail.css', function(req, res) {
    res.sendFile(__dirname + "/dist/css/tltd/page/tradeDetail.css");
});
app.get('/dist/css/tltd/page/lodin.css', function(req, res) {
    res.sendFile(__dirname + "/dist/css/tltd/page/lodin.css");
});
app.get('/dist/css/tltd/page/merchantHome.css', function(req, res) {
    res.sendFile(__dirname + "/dist/css/tltd/page/merchantHome.css");
});
app.get('/dist/css/tltd/page/orderDetail.css', function(req, res) {
    res.sendFile(__dirname + "/dist/css/tltd/page/orderDetail.css");
});
app.get('/dist/css/tltd/page/userSettings.css', function(req, res) {
    res.sendFile(__dirname + "/dist/css/tltd/page/userSettings.css");
});
app.get('/dist/css/tltd/page/staffHome.css', function(req, res) {
    res.sendFile(__dirname + "/dist/css/tltd/page/staffHome.css");
});
app.get('/dist/css/tltd/page/staffRecord.css', function(req, res) {
    res.sendFile(__dirname + "/dist/css/tltd/page/staffRecord.css");
});



/*-------img----------*/
app.get('/dist/images/tltd/fanhui.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/tltd/fanhui.png");
});
app.get('/dist/images/tltd/fanhui.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/tltd/fanhui.png");
});
app.get('/dist/images/tltd/ajax-loader.gif', function(req, res) {
    res.sendFile(__dirname + "/dist/images/tltd/ajax-loader.gif");
});
app.get('/dist/images/tltd/fenqixiaofei_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/tltd/fenqixiaofei_icon.png");
});
app.get('/dist/images/tltd/header.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/tltd/header.png");
});
app.get('/dist/images/tltd/yanjing_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/tltd/yanjing_icon.png");
});
app.get('/dist/images/tltd/close_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/tltd/close_icon.png");
});
app.get('/dist/images/tltd/header.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/tltd/header.png");
});
app.get('/images/tltd/header.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/tltd/header.png");
});
app.get('/dist/images/tltd/header.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/tltd/header.png");
});
app.get('/dist/css/fonts/lyicon.ttf?dvqwk5', function(req, res) {
    res.sendFile(__dirname + "/dist/css/fonts/lyicon.ttf?dvqwk5");
});
app.get('/dist/images/tltd/erweima_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/tltd/erweima_icon.png");
});
app.get('/dist/images/tltd/yibangding_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/tltd/yibangding_icon.png");
});
app.get('/dist/images/tltd/weibangding_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/tltd/weibangding_icon.png");
});


/*******接口*********/
app.post('/FuLiBao/TradeTransInfoSevlet', urlencodedParser, function(req, res) {
    /*    res.writeHead(200, {
            'Content-Type': 'text/html;charset=utf-8'
        }); //设置response编码为utf-8*/
    // application/json  接口返回json数据
    // charset=utf-8 解决json数据中中文乱码
    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/FuLiBao/TradeTransInfoSevlet"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
/*    var singInData = monidata.gettstdshjyjl(req.body);
    console.log(JSON.stringify(singInData));
    res.end(JSON.stringify(singInData));*/
});
app.post('/FuLiBao//tltd/login', urlencodedParser, function(req, res) {
    /*    res.writeHead(200, {
            'Content-Type': 'text/html;charset=utf-8'
        }); //设置response编码为utf-8*/
    // application/json  接口返回json数据
    // charset=utf-8 解决json数据中中文乱码
    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/FuLiBao/tltd/login"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
/*    */
});
app.post('/FuLiBao/MerInfoServlet', urlencodedParser, function(req, res) {

    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/FuLiBao/MerInfoServlet"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
/*    */
});
app.post('/FuLiBao/TltdOneClickLoginServlet', urlencodedParser, function(req, res) {

    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/FuLiBao/TltdOneClickLoginServlet"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
/*    */
});

app.post('/FuLiBao/CashierTradeServlet', urlencodedParser, function(req, res) {

    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/FuLiBao/CashierTradeServlet"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
/*    */
});
app.post('/FuLiBao/MerRelationServlet', urlencodedParser, function(req, res) {

    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/FuLiBao/MerRelationServlet"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
/*    */
});

/* 撤销交易 */
app.post('/FuLiBao/MerConsumeRevokeServlet', urlencodedParser, function(req, res) {

    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/FuLiBao/MerConsumeRevokeServlet"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
/*    */
});


/* 部分退货测算 */
app.post('/FuLiBao/TransPartRefundTypeServlet', urlencodedParser, function(req, res) {

    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/FuLiBao/TransPartRefundTypeServlet"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
/*    */
});

/* 部分退货接口 */
app.post('/FuLiBao/MerDopeRefundsServlet', urlencodedParser, function(req, res) {

    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/FuLiBao/MerDopeRefundsServlet"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
/*    */
});

app.post('/FuLiBao/IsSignServlet', urlencodedParser, function(req, res) {

    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/FuLiBao/IsSignServlet"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
/*    */
});
app.post('/FuLiBao/AcctQueryServlet', urlencodedParser, function(req, res) {

    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/FuLiBao/AcctQueryServlet"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
/*    */
});

app.post('/FuLiBao/WxConfigServlet', urlencodedParser, function(req, res) {

    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/FuLiBao/WxConfigServlet"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
/*    */
});

app.post('/FuLiBao/SearchCahierServlet', urlencodedParser, function(req, res) {

    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/FuLiBao/SearchCahierServlet"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
/*    */
});
app.post('/FuLiBao/tltd/sms/send', urlencodedParser, function(req, res) {

    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/FuLiBao/tltd/sms/send"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
/*    */
});

app.post('/FuLiBao/MerExtraSearchServlet', urlencodedParser, function(req, res) {

    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/FuLiBao/MerExtraSearchServlet"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
/*    */
});

app.post('/FuLiBao/AccBalanceServlet', urlencodedParser, function(req, res) {

    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/FuLiBao/AccBalanceServlet"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
/*    */
});

app.post('/FuLiBao/CashierIsOpenAccountServlet', urlencodedParser, function(req, res) {

    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/FuLiBao/CashierIsOpenAccountServlet"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
//        res.end(data);
    });
    agentObjet.request();
    var singInData = monidata.getIsOpenAccount(req.body);
    console.log(JSON.stringify(singInData));
    res.end(JSON.stringify(singInData));
});


app.post('/FuLiBao/BalanceServlet', urlencodedParser, function(req, res) {

    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/FuLiBao/BalanceServlet"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
/*    */
});

app.post('/FuLiBao/MerRefundsServlet', urlencodedParser, function(req, res) {

    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/FuLiBao/MerRefundsServlet"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
/*    */
});

app.post('/FuLiBao/TransDetailServlet', urlencodedParser, function(req, res) {

    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/FuLiBao/TransDetailServlet"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
/*    */
});

app.post('/FuLiBao/CashierTradeDetailServlet', urlencodedParser, function(req, res) {

    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/FuLiBao/CashierTradeDetailServlet"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
/*    */
});


app.post('/FuLiBao/LFQCreateOrderServlet', urlencodedParser, function(req, res) {

    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/FuLiBao/LFQCreateOrderServlet"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
/*    */
});


app.post('/FuLiBao/MerRefundsAmtServlet', urlencodedParser, function(req, res) {

    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/FuLiBao/MerRefundsAmtServlet"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
/*    var merRefundData = monidata.getMerRefundsServlet(req.body);
    console.log(JSON.stringify(merRefundData));
    res.end(JSON.stringify(merRefundData));*/
});




var server = app.listen(9090, function() {

    var host = server.address().address;
    var port = server.address().port;

    console.log("应用实例，访问地址为 http://%s:%s", host, port)

});
